package com.testing.thread;

import java.util.concurrent.*;

/**
 * @author Administrator
 */
public class CreateThread {

    static class TestThread extends Thread{
        @Override
        public void run() {
            System.out.println("第一种方式继承Thread");
        }
    }

    static class TestRunnable implements Runnable{
        @Override
        public void run() {
            System.out.println("第二方式实现Runnable");
        }
    }

    static class TestCallAble implements Callable<String> {
        @Override
        public String call() throws Exception {
            System.out.println("第三方式实现Callable");
            return "Success";
        }
    }

    public static void main(String[] args) {
        // 第一种启动方式extends Thread的启动方式
        new TestThread().start();

        // 第二种启动方式，implements Runnable接口的只能用这种方式启动
        new Thread(new TestRunnable()).start();

        // 第三种
        new Thread(() ->{
            System.out.println("第三种直接启动");
        }).start();
        // 第四种,有返回值
        Thread thread = new Thread(new FutureTask<String>(new TestCallAble()));
        System.out.println("第四种有返回值");
        thread.start();

        ExecutorService service = Executors.newFixedThreadPool(10);
        service.execute(() ->{
            System.out.println("第五种线程池");
        });
        service.shutdown();
    }
}
